﻿using Grow.Module.Options;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Grow.AspNetCore.Options
{
    public class OptionsManager : IOptionsManager
    {
        private readonly ConfigurationManager _configurationManager;
        private readonly IServiceCollection _serviceCollection;
        private readonly IOptionsBind _optionsBind;

        public OptionsManager(ConfigurationManager configurationManager, IServiceCollection serviceCollection)
        {
            _configurationManager = configurationManager;
            _serviceCollection = serviceCollection;

            _optionsBind = new OptionsBind(_configurationManager);

        }

        public void AddOptions<TOptions>(Action<TOptions> optionsAction) where TOptions : class, IOptions
        {
            _ = _serviceCollection.Configure(optionsAction);
        }

        public void AddOptions<TOptions>(string name, Action<TOptions> optionsAction) where TOptions : class, IOptions
        {
            _ = _serviceCollection.Configure(name, optionsAction);
        }


        public IOptionsBind GetOptionsBind()
        {
            return _optionsBind;
        }


    }
}
